package com.oreilly.ez.base;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig  implements WebSocketMessageBrokerConfigurer{

//    @Bean
//    public ServerEndpointExporter serverEndpointExporter(){
//
//        return new ServerEndpointExporter();
//    }


    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {

        registry.addEndpoint("/endpointWisely").setAllowedOrigins("*").withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {

        //客户端 订阅服务的前缀
        registry.enableSimpleBroker("/topic", "/user");

        //开启 一对一 发送消息
        registry.setUserDestinationPrefix("/user");


        //定义websocket 前缀
        registry.setApplicationDestinationPrefixes("/ws-push");
    }
}
